package com.coolgor.coldot.dao.stock;

import com.coolgor.coldot.entity.stock.MarketDaily;
import org.apache.ibatis.annotations.*;
import java.util.List;


@Mapper
public interface MarketDailyDao {

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_stock_market_daily
			WHERE
				record_id = #{recordID}
		</script>
	""")
	@Results(id = "MarketDailyMap", value = {
		@Result(property = "recordID", column = "record_id"),
		@Result(property = "code", column = "code"),
		@Result(property = "name", column = "name"),
		@Result(property = "yesterdayClosePrice", column = "yesterday_close_price"),
		@Result(property = "openPrice", column = "open_price"),
		@Result(property = "currentPrice", column = "current_price"),
		@Result(property = "highPrice", column = "high_price"),
		@Result(property = "lowPrice", column = "low_price"),
		@Result(property = "bidPrice", column = "bid_price"),
		@Result(property = "askPrice", column = "ask_price"),
		@Result(property = "tradeVolume", column = "trade_volume"),
		@Result(property = "transactionAmount", column = "transaction_amount"),
		@Result(property = "bidVolume1", column = "bid_volume_1"),
		@Result(property = "bidQuote1", column = "bid_quote_1"),
		@Result(property = "bidVolume2", column = "bid_volume_2"),
		@Result(property = "bidQuote2", column = "bid_quote_2"),
		@Result(property = "bidVolume3", column = "bid_volume_3"),
		@Result(property = "bidQuote3", column = "bid_quote_3"),
		@Result(property = "bidVolume4", column = "bid_volume_4"),
		@Result(property = "bidQuote4", column = "bid_quote_4"),
		@Result(property = "bidVolume5", column = "bid_volume_5"),
		@Result(property = "bidQuote5", column = "bid_quote_5"),
		@Result(property = "askVolume1", column = "ask_volume_1"),
		@Result(property = "askQuote1", column = "ask_quote_1"),
		@Result(property = "askVolume2", column = "ask_volume_2"),
		@Result(property = "askQuote2", column = "ask_quote_2"),
		@Result(property = "askVolume3", column = "ask_volume_3"),
		@Result(property = "askQuote3", column = "ask_quote_3"),
		@Result(property = "askVolume4", column = "ask_volume_4"),
		@Result(property = "askQuote4", column = "ask_quote_4"),
		@Result(property = "askVolume5", column = "ask_volume_5"),
		@Result(property = "askQuote5", column = "ask_quote_5"),
		@Result(property = "marketDay", column = "market_day"),
		@Result(property = "marketTime", column = "market_time"),
		@Result(property = "source", column = "source"),
		@Result(property = "touchTime", column = "touch_time"),
		@Result(property = "remark", column = "remark")
	})
	MarketDaily queryByID(@Param("recordID") Long recordID);

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_stock_market_daily
			<where>
				<if test="marketDailyCondition.recordID != null">
					and record_id = #{marketDailyCondition.recordID}
				</if>
				<if test="marketDailyCondition.code != null">
					and code like '${marketDailyCondition.code}'
				</if>
				<if test="marketDailyCondition.name != null">
					and name like '${marketDailyCondition.name}'
				</if>
				<if test="marketDailyCondition.yesterdayClosePrice != null">
					and yesterday_close_price like '${marketDailyCondition.yesterdayClosePrice}'
				</if>
				<if test="marketDailyCondition.openPrice != null">
					and open_price like '${marketDailyCondition.openPrice}'
				</if>
				<if test="marketDailyCondition.currentPrice != null">
					and current_price like '${marketDailyCondition.currentPrice}'
				</if>
				<if test="marketDailyCondition.highPrice != null">
					and high_price like '${marketDailyCondition.highPrice}'
				</if>
				<if test="marketDailyCondition.lowPrice != null">
					and low_price like '${marketDailyCondition.lowPrice}'
				</if>
				<if test="marketDailyCondition.bidPrice != null">
					and bid_price like '${marketDailyCondition.bidPrice}'
				</if>
				<if test="marketDailyCondition.askPrice != null">
					and ask_price like '${marketDailyCondition.askPrice}'
				</if>
				<if test="marketDailyCondition.tradeVolume != null">
					and trade_volume = #{marketDailyCondition.tradeVolume}
				</if>
				<if test="marketDailyCondition.transactionAmount != null">
					and transaction_amount like '${marketDailyCondition.transactionAmount}'
				</if>
				<if test="marketDailyCondition.bidVolume1 != null">
					and bid_volume_1 = #{marketDailyCondition.bidVolume1}
				</if>
				<if test="marketDailyCondition.bidQuote1 != null">
					and bid_quote_1 like '${marketDailyCondition.bidQuote1}'
				</if>
				<if test="marketDailyCondition.bidVolume2 != null">
					and bid_volume_2 = #{marketDailyCondition.bidVolume2}
				</if>
				<if test="marketDailyCondition.bidQuote2 != null">
					and bid_quote_2 like '${marketDailyCondition.bidQuote2}'
				</if>
				<if test="marketDailyCondition.bidVolume3 != null">
					and bid_volume_3 = #{marketDailyCondition.bidVolume3}
				</if>
				<if test="marketDailyCondition.bidQuote3 != null">
					and bid_quote_3 like '${marketDailyCondition.bidQuote3}'
				</if>
				<if test="marketDailyCondition.bidVolume4 != null">
					and bid_volume_4 = #{marketDailyCondition.bidVolume4}
				</if>
				<if test="marketDailyCondition.bidQuote4 != null">
					and bid_quote_4 like '${marketDailyCondition.bidQuote4}'
				</if>
				<if test="marketDailyCondition.bidVolume5 != null">
					and bid_volume_5 = #{marketDailyCondition.bidVolume5}
				</if>
				<if test="marketDailyCondition.bidQuote5 != null">
					and bid_quote_5 like '${marketDailyCondition.bidQuote5}'
				</if>
				<if test="marketDailyCondition.askVolume1 != null">
					and ask_volume_1 = #{marketDailyCondition.askVolume1}
				</if>
				<if test="marketDailyCondition.askQuote1 != null">
					and ask_quote_1 like '${marketDailyCondition.askQuote1}'
				</if>
				<if test="marketDailyCondition.askVolume2 != null">
					and ask_volume_2 = #{marketDailyCondition.askVolume2}
				</if>
				<if test="marketDailyCondition.askQuote2 != null">
					and ask_quote_2 like '${marketDailyCondition.askQuote2}'
				</if>
				<if test="marketDailyCondition.askVolume3 != null">
					and ask_volume_3 = #{marketDailyCondition.askVolume3}
				</if>
				<if test="marketDailyCondition.askQuote3 != null">
					and ask_quote_3 like '${marketDailyCondition.askQuote3}'
				</if>
				<if test="marketDailyCondition.askVolume4 != null">
					and ask_volume_4 = #{marketDailyCondition.askVolume4}
				</if>
				<if test="marketDailyCondition.askQuote4 != null">
					and ask_quote_4 like '${marketDailyCondition.askQuote4}'
				</if>
				<if test="marketDailyCondition.askVolume5 != null">
					and ask_volume_5 = #{marketDailyCondition.askVolume5}
				</if>
				<if test="marketDailyCondition.askQuote5 != null">
					and ask_quote_5 like '${marketDailyCondition.askQuote5}'
				</if>
				<if test="marketDailyCondition.marketDay != null">
					and market_day = #{marketDailyCondition.marketDay}
				</if>
				<if test="marketDailyCondition.marketDay != null">
					and <![CDATA[ market_day >= #{marketDailyCondition.marketDay,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.marketDay != null">
					and <![CDATA[ market_day <= #{marketDailyCondition.marketDay,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.marketTime != null">
					and market_time = #{marketDailyCondition.marketTime}
				</if>
				<if test="marketDailyCondition.marketTime != null">
					and <![CDATA[ market_time >= #{marketDailyCondition.marketTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.marketTime != null">
					and <![CDATA[ market_time <= #{marketDailyCondition.marketTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.source != null">
					and source like '${marketDailyCondition.source}'
				</if>
				<if test="marketDailyCondition.touchTime != null">
					and touch_time = #{marketDailyCondition.touchTime}
				</if>
				<if test="marketDailyCondition.touchTime != null">
					and <![CDATA[ touch_time >= #{marketDailyCondition.touchTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.touchTime != null">
					and <![CDATA[ touch_time <= #{marketDailyCondition.touchTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.remark != null">
					and remark like '${marketDailyCondition.remark}'
				</if>
			</where>
			LIMIT #{rowIndex},#{pageSize};
		</script>
	""")
	@ResultMap("MarketDailyMap")
	List<MarketDaily> queryList(@Param("marketDailyCondition") MarketDaily marketDailyCondition,
							@Param("rowIndex") int rowIndex,
							@Param("pageSize") int pageSize);

	@Select("""
		<script>
			SELECT
				count(1)
			FROM
				tb_coldot_stock_market_daily
			<where>
				<if test="marketDailyCondition.recordID != null">
					and record_id = #{marketDailyCondition.recordID}
				</if>
				<if test="marketDailyCondition.code != null">
					and code like '${marketDailyCondition.code}'
				</if>
				<if test="marketDailyCondition.name != null">
					and name like '${marketDailyCondition.name}'
				</if>
				<if test="marketDailyCondition.yesterdayClosePrice != null">
					and yesterday_close_price like '${marketDailyCondition.yesterdayClosePrice}'
				</if>
				<if test="marketDailyCondition.openPrice != null">
					and open_price like '${marketDailyCondition.openPrice}'
				</if>
				<if test="marketDailyCondition.currentPrice != null">
					and current_price like '${marketDailyCondition.currentPrice}'
				</if>
				<if test="marketDailyCondition.highPrice != null">
					and high_price like '${marketDailyCondition.highPrice}'
				</if>
				<if test="marketDailyCondition.lowPrice != null">
					and low_price like '${marketDailyCondition.lowPrice}'
				</if>
				<if test="marketDailyCondition.bidPrice != null">
					and bid_price like '${marketDailyCondition.bidPrice}'
				</if>
				<if test="marketDailyCondition.askPrice != null">
					and ask_price like '${marketDailyCondition.askPrice}'
				</if>
				<if test="marketDailyCondition.tradeVolume != null">
					and trade_volume = #{marketDailyCondition.tradeVolume}
				</if>
				<if test="marketDailyCondition.transactionAmount != null">
					and transaction_amount like '${marketDailyCondition.transactionAmount}'
				</if>
				<if test="marketDailyCondition.bidVolume1 != null">
					and bid_volume_1 = #{marketDailyCondition.bidVolume1}
				</if>
				<if test="marketDailyCondition.bidQuote1 != null">
					and bid_quote_1 like '${marketDailyCondition.bidQuote1}'
				</if>
				<if test="marketDailyCondition.bidVolume2 != null">
					and bid_volume_2 = #{marketDailyCondition.bidVolume2}
				</if>
				<if test="marketDailyCondition.bidQuote2 != null">
					and bid_quote_2 like '${marketDailyCondition.bidQuote2}'
				</if>
				<if test="marketDailyCondition.bidVolume3 != null">
					and bid_volume_3 = #{marketDailyCondition.bidVolume3}
				</if>
				<if test="marketDailyCondition.bidQuote3 != null">
					and bid_quote_3 like '${marketDailyCondition.bidQuote3}'
				</if>
				<if test="marketDailyCondition.bidVolume4 != null">
					and bid_volume_4 = #{marketDailyCondition.bidVolume4}
				</if>
				<if test="marketDailyCondition.bidQuote4 != null">
					and bid_quote_4 like '${marketDailyCondition.bidQuote4}'
				</if>
				<if test="marketDailyCondition.bidVolume5 != null">
					and bid_volume_5 = #{marketDailyCondition.bidVolume5}
				</if>
				<if test="marketDailyCondition.bidQuote5 != null">
					and bid_quote_5 like '${marketDailyCondition.bidQuote5}'
				</if>
				<if test="marketDailyCondition.askVolume1 != null">
					and ask_volume_1 = #{marketDailyCondition.askVolume1}
				</if>
				<if test="marketDailyCondition.askQuote1 != null">
					and ask_quote_1 like '${marketDailyCondition.askQuote1}'
				</if>
				<if test="marketDailyCondition.askVolume2 != null">
					and ask_volume_2 = #{marketDailyCondition.askVolume2}
				</if>
				<if test="marketDailyCondition.askQuote2 != null">
					and ask_quote_2 like '${marketDailyCondition.askQuote2}'
				</if>
				<if test="marketDailyCondition.askVolume3 != null">
					and ask_volume_3 = #{marketDailyCondition.askVolume3}
				</if>
				<if test="marketDailyCondition.askQuote3 != null">
					and ask_quote_3 like '${marketDailyCondition.askQuote3}'
				</if>
				<if test="marketDailyCondition.askVolume4 != null">
					and ask_volume_4 = #{marketDailyCondition.askVolume4}
				</if>
				<if test="marketDailyCondition.askQuote4 != null">
					and ask_quote_4 like '${marketDailyCondition.askQuote4}'
				</if>
				<if test="marketDailyCondition.askVolume5 != null">
					and ask_volume_5 = #{marketDailyCondition.askVolume5}
				</if>
				<if test="marketDailyCondition.askQuote5 != null">
					and ask_quote_5 like '${marketDailyCondition.askQuote5}'
				</if>
				<if test="marketDailyCondition.marketDay != null">
					and market_day = #{marketDailyCondition.marketDay}
				</if>
				<if test="marketDailyCondition.marketDay != null">
					and <![CDATA[ market_day >= #{marketDailyCondition.marketDay,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.marketDay != null">
					and <![CDATA[ market_day <= #{marketDailyCondition.marketDay,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.marketTime != null">
					and market_time = #{marketDailyCondition.marketTime}
				</if>
				<if test="marketDailyCondition.marketTime != null">
					and <![CDATA[ market_time >= #{marketDailyCondition.marketTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.marketTime != null">
					and <![CDATA[ market_time <= #{marketDailyCondition.marketTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.source != null">
					and source like '${marketDailyCondition.source}'
				</if>
				<if test="marketDailyCondition.touchTime != null">
					and touch_time = #{marketDailyCondition.touchTime}
				</if>
				<if test="marketDailyCondition.touchTime != null">
					and <![CDATA[ touch_time >= #{marketDailyCondition.touchTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.touchTime != null">
					and <![CDATA[ touch_time <= #{marketDailyCondition.touchTime,jdbcType=DATE} ]]>
				</if>
				<if test="marketDailyCondition.remark != null">
					and remark like '${marketDailyCondition.remark}'
				</if>
			</where>
		</script>
	""")
	int queryCount(@Param("marketDailyCondition") MarketDaily marketDailyCondition);

	@Insert("""
		<script>
			INSERT INTO tb_coldot_stock_market_daily (
				code,
				name,
				yesterday_close_price,
				open_price,
				current_price,
				high_price,
				low_price,
				bid_price,
				ask_price,
				trade_volume,
				transaction_amount,
				bid_volume_1,
				bid_quote_1,
				bid_volume_2,
				bid_quote_2,
				bid_volume_3,
				bid_quote_3,
				bid_volume_4,
				bid_quote_4,
				bid_volume_5,
				bid_quote_5,
				ask_volume_1,
				ask_quote_1,
				ask_volume_2,
				ask_quote_2,
				ask_volume_3,
				ask_quote_3,
				ask_volume_4,
				ask_quote_4,
				ask_volume_5,
				ask_quote_5,
				market_day,
				market_time,
				source,
				touch_time,
				remark
			) VALUES (
				#{code},
				#{name},
				#{yesterdayClosePrice},
				#{openPrice},
				#{currentPrice},
				#{highPrice},
				#{lowPrice},
				#{bidPrice},
				#{askPrice},
				#{tradeVolume},
				#{transactionAmount},
				#{bidVolume1},
				#{bidQuote1},
				#{bidVolume2},
				#{bidQuote2},
				#{bidVolume3},
				#{bidQuote3},
				#{bidVolume4},
				#{bidQuote4},
				#{bidVolume5},
				#{bidQuote5},
				#{askVolume1},
				#{askQuote1},
				#{askVolume2},
				#{askQuote2},
				#{askVolume3},
				#{askQuote3},
				#{askVolume4},
				#{askQuote4},
				#{askVolume5},
				#{askQuote5},
				#{marketDay},
				#{marketTime},
				#{source},
				#{touchTime},
				#{remark}
			)
		</script>
	""")
	@Options(useGeneratedKeys = true, keyColumn = "record_id", keyProperty = "recordID")
	int insert(MarketDaily marketDaily);

	@Update("""
		<script>
			UPDATE tb_coldot_stock_market_daily
			<set>
				<if test="code != null">code=#{code},</if>
				<if test="name != null">name=#{name},</if>
				<if test="yesterdayClosePrice != null">yesterday_close_price=#{yesterdayClosePrice},</if>
				<if test="openPrice != null">open_price=#{openPrice},</if>
				<if test="currentPrice != null">current_price=#{currentPrice},</if>
				<if test="highPrice != null">high_price=#{highPrice},</if>
				<if test="lowPrice != null">low_price=#{lowPrice},</if>
				<if test="bidPrice != null">bid_price=#{bidPrice},</if>
				<if test="askPrice != null">ask_price=#{askPrice},</if>
				<if test="tradeVolume != null">trade_volume=#{tradeVolume},</if>
				<if test="transactionAmount != null">transaction_amount=#{transactionAmount},</if>
				<if test="bidVolume1 != null">bid_volume_1=#{bidVolume1},</if>
				<if test="bidQuote1 != null">bid_quote_1=#{bidQuote1},</if>
				<if test="bidVolume2 != null">bid_volume_2=#{bidVolume2},</if>
				<if test="bidQuote2 != null">bid_quote_2=#{bidQuote2},</if>
				<if test="bidVolume3 != null">bid_volume_3=#{bidVolume3},</if>
				<if test="bidQuote3 != null">bid_quote_3=#{bidQuote3},</if>
				<if test="bidVolume4 != null">bid_volume_4=#{bidVolume4},</if>
				<if test="bidQuote4 != null">bid_quote_4=#{bidQuote4},</if>
				<if test="bidVolume5 != null">bid_volume_5=#{bidVolume5},</if>
				<if test="bidQuote5 != null">bid_quote_5=#{bidQuote5},</if>
				<if test="askVolume1 != null">ask_volume_1=#{askVolume1},</if>
				<if test="askQuote1 != null">ask_quote_1=#{askQuote1},</if>
				<if test="askVolume2 != null">ask_volume_2=#{askVolume2},</if>
				<if test="askQuote2 != null">ask_quote_2=#{askQuote2},</if>
				<if test="askVolume3 != null">ask_volume_3=#{askVolume3},</if>
				<if test="askQuote3 != null">ask_quote_3=#{askQuote3},</if>
				<if test="askVolume4 != null">ask_volume_4=#{askVolume4},</if>
				<if test="askQuote4 != null">ask_quote_4=#{askQuote4},</if>
				<if test="askVolume5 != null">ask_volume_5=#{askVolume5},</if>
				<if test="askQuote5 != null">ask_quote_5=#{askQuote5},</if>
				<if test="marketDay != null">market_day=#{marketDay},</if>
				<if test="marketTime != null">market_time=#{marketTime},</if>
				<if test="source != null">source=#{source},</if>
				<if test="touchTime != null">touch_time=#{touchTime},</if>
				<if test="remark != null">remark=#{remark}</if>
			</set>
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int update(MarketDaily marketDaily);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_stock_market_daily
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int delete(Long recordID);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_stock_market_daily
			WHERE
				record_id IN
				<foreach collection="list" item="recordID" open="(" separator="," close=")">
					#{recordID}
				</foreach>
		</script>
	""")
	int deleteBatch(List<Long> idList);

}